package com.LC.DAO;

import com.LC.Entity.CheckGroup;
import com.LC.Entity.CheckItem;
import com.LC.Entity.SetMeal;
import com.github.pagehelper.Page;
import org.apache.ibatis.annotations.*;

import java.util.List;


@Mapper
public interface SetMealDAO {

    @Select("select * from t_checkgroup")
    public List<CheckGroup> findAllCheckGroup();

    @Select("<script>" +
            "select * from t_setmeal" +
            "<if test='value != null and value.length > 0'>" +
            "where code = #{value} or name = #{value} or helpCode = #{value}"     +
            "</if>"     +
            "</script>")
    public Page<SetMeal> findSetMealByCondition(String queryString);

    @Insert("insert into t_setmeal(name,code,helpCode,sex,age,price,remark,attention,img) values (#{name}," +
            "#{code},#{helpCode},#{sex},#{age},#{price},#{remark},#{attention},#{img})")
    @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
    public void addTot_setmeal(SetMeal setMeal);

    @Insert("insert into t_setmeal_checkgroup values(#{mealId},#{checkGroupId})")
    public void addTot_setmeal_checkgroup(@Param("mealId") int mealId, @Param("checkGroupId") int checkGroupId);

    @Select("select * from t_setmeal")
    public List<SetMeal> findAllSetMeal();

    @Select("select * from t_setmeal where id = #{id}")
    public SetMeal findById(int id);

    @Select("SELECT * FROM t_checkgroup tcg,t_setmeal_checkgroup tsmcg  WHERE  tsmcg.`setmeal_id` = #{MealId} AND tsmcg.`checkgroup_id`=tcg.`id`")
    public List<CheckGroup> findByMealId(int MealId);

    @Select("SELECT * FROM t_checkgroup_checkitem tcgci,t_checkitem tci WHERE tcgci.`checkgroup_id` = #{groupId} AND tci.`id` = tcgci.`checkitem_id`")
    public List<CheckItem> findByGroupId(int groupId);
    
    @Select("select setmealId from t_order")
    public List<Integer> findMealIdFromOrderTable();
    
    @Select("select count(*) from t_order where setmealId = #{mealId} ")
    public int mealCountFromOrderTable(int mealId);
    
    @Delete("delete from t_setmeal_checkgroup where setmeal_id = #{mealId}")
    public void deleteCheckGroupIdByMealId(int mealId);
    
    @Update("update t_setmeal set name = #{name},code = #{code},helpCode = #{helpCode},sex = #{sex}," +
      "age = #{age},price = #{price},remark = #{remark},attention = #{attention} where id = #{id}")
    public void updateMeal(SetMeal setMeal);
    
    @Delete("delete from t_setmeal where id = #{mealId}")
    public void delete(int mealId);
    
    
    
}
